package com.yixin.histrix;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class HelloService {
    @Autowired
    RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "error")
    public String hello() {
        return restTemplate.getForObject("http://provider/hello", String.class);
    }
    /**
       * 注意，这个方法名字要和 fallbackMethod 一致
       * 方法返回值也要和对应的方法一致
       * @return
       */
    public String error(){
        return "error";
    }

}
